<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../common/css/insert.css">
<title>CheckedCommentSearch</title>
</head>
<body>
	<div id="searchInfo">
		<form>	
			<div class="form-group">
				<label>书籍ID：</label> <input class="form-control" id="idEnter"
					type="text" name="book_id" placeholder="输入书籍ID">
			</div>
			<input class="btn btn-primary" type="button" value="搜索"
				onclick="toSearch()"> <input class="btn btn-danger"
				type="reset" value="重置">
		</form>
	</div>
	<br><hr><br>
	<div>
		<label>结果显示：</label>
	</div>
	<div id="searchResults">
	</div>
	
	
	<script>
	function toSearch(){
		
		var bookid = $('#idEnter').val();

		var jo = {
			"bookid":bookid,
		};
		
		$(document).ready(function() {
			$.ajax({
				type : "post",
				url : "../getBookComments.action",
				dataType : "json",
				data : jo,
				success : function(comments) {
					
					var table = document.getElementById('searchResults');
					
					var tab="<table border='5' bordercolor='blue' width='100%' height='auto'>";


					//循环行
					for(var i=0;i<=comments.length;i++)
			        {
						if(i==0){
							tab+="<tr>";
							tab+="<td>评论ID</td>";
				       		tab+="<td>用户ID</td>";
				       	 	tab+="<td>书籍ID</td>";
				       		tab+="<td>评论时间</td>";
				       		tab+="<td>评论状态</td>";
				       	 	tab+="<td>评论内容</td>";
				       		tab+="<td>评星</td>";
				            tab+="</tr>";
						}else{
			            	tab+="<tr>";
			            	tab+="<td>"+comments[i-1].commentid+"</td>";
			       			tab+="<td>"+comments[i-1].userid+"</td>";
			       	 		tab+="<td>"+comments[i-1].bookid+"</td>";
			       			tab+="<td>"+comments[i-1].time+"</td>";
			       			tab+="<td>"+comments[i-1].state+"</td>";
			       	 		tab+="<td>"+comments[i-1].content+"</td>";
			       			tab+="<td>"+comments[i-1].star+"</td>";
			            	tab+="</tr>";
						}
			        }
					
					tab+="</table>";
			       	table.innerHTML=tab;

				}
			});
		});
	}
	</script>
	<script src="../js/jquery-1.9.1.min.js"></script>  
	<script src="../js/jquery.form.js"></script> 
</body>
</html>